package collectionhomework;

import java.util.ArrayList;
import java.util.List;

public class ListDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("one");
        System.out.println("list:"+list); //list:[one, two, three, four, five, one]

        String e = list.get(3); //获取下标3位置的元素
        System.out.println(e); //four
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println("-----------------------------");

        list.set(2,"six"); //将list中下标为2的元素设置为six----常规用法
        //String old = list.set(2,"six"); //将list中下标为2的元素设置为six,同时返回原数据赋值给old
        //System.out.println(old); //three
        System.out.println("list:"+list); //list:[one, two, six, four, five, one]

    }
}
